﻿@using Fly.Domain.Models;
@using Fly.Domain.Infrastructure;
@model GetPagingResponse<Post>
@{
    ViewBag.Title = "全部求解";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
}


<div class="main layui-clear">
    <div class="wrap">
        <div class="content" style="margin-right:0">
            <div class="fly-tab">
                <span>
                    <a href="@Url.Action("Index","Post")">全部</a>
                    <a href="@Url.Action("Unsolved","Post")">未结帖</a>
                    <a href="@Url.Action("Solved","Post")">已采纳</a>
                    <a href="@Url.Action("Wonderful","Post")">精帖</a>
                    @if (HttpContext.Current.User.Identity.IsAuthenticated)
                    {
                        <a href="@Url.Action("Index", "Account")">我的帖</a>
                    }
                </span>
                <form action="http://cn.bing.com/search" class="fly-search">
                    <i class="iconfont icon-sousuo"></i>
                    <input class="layui-input" autocomplete="off" placeholder="搜索内容，回车跳转" type="text" name="q">
                </form>
                <a href="@Url.Action("Add","Post")" class="layui-btn jie-add">发布问题</a>
            </div>

            @if (Model.IsSuccess)
            {
                <ul class="fly-list">
                    @foreach (var item in Model.Pages.Items)
                    {
                        <li class="fly-list-li">
                            <a href="@Url.Action("Home", "Account", new { userId = item.UserId })" class="fly-list-avatar">
                                <img src="@item.User.HeadPortrait" alt="">
                            </a>
                            <h2 class="fly-tip">
                                <a href="@Url.Action("Detail", "Post", new { postId = @item.Id })">@item.Title</a>
                                @if (item.IsTop)
                                {
                                    <span class="fly-tip-stick">置顶</span>
                                }
                                @if (item.IsBoutique)
                                {
                                    <span class="fly-tip-jing">精帖</span>
                                }
                            </h2>
                            <p>
                                <span><a href="@Url.Action("Home", "Account", new { userId = item.UserId })">@item.User.Nickname</a></span>
                                <span>@item.TimeAgo</span>
                                <span>@item.PostCategory.CategoryName</span>
                                <span class="fly-list-hint">
                                    <i class="iconfont" title="回答">&#xe60c;</i> @item.CommentCount
                                    <i class="iconfont" title="人气">&#xe60b;</i> @item.Hits
                                </span>
                            </p>
                        </li>
                    }
                </ul>
            }
            else
            {
                <div class="fly-none">并无相关数据</div>
            }
            <!--分页容器-->
            <div style="text-align: center" id="paged">

            </div>
        </div>
    </div>
</div>
@section scripts{
    <script>
        layui.use(['laypage', 'jquery'], function () {
            var $ = layui.jquery;

            layui.laypage({
                cont: 'paged',
                pages: '@(Model.IsSuccess?Model.Pages.TotalPages:0)',
                curr: '@(Model.IsSuccess?Model.Pages.CurrentPage:1)',
                jump: function (obj, first) {
                    var curr = obj.curr;
                    if (!first) {
                        var pathname = location.pathname.substring(0, location.pathname.indexOf('_'));

                        if (location.pathname === '@Url.Action("Index", "Post")' || pathname === '@Url.Action("Index","Post")/page') {
                            location.href = '@Url.Action("Index","Post")/page_' + curr;
                        } else if (location.pathname === '@Url.Action("Unsolved", "Post")' || pathname === '@Url.Action("Unsolved", "Post")') {
                            location.href = '@Url.Action("Unsolved", "Post")_page_' + curr;
                        } else if (location.pathname === '@Url.Action("Solved", "Post")' || pathname === '@Url.Action("Solved", "Post")') {
                            location.href = '@Url.Action("Solved", "Post")_page_' + curr;
                        } else if (location.pathname === '@Url.Action("Wonderful", "Post")' || pathname === '@Url.Action("Wonderful", "Post")') {
                            location.href = '@Url.Action("Wonderful", "Post")_page_' + curr;
                        }
                    }
                }
            });
            $('.fly-tab').find('span>a').each(function () {
                var $that = $(this);
                var pathname = location.pathname.substring(0, location.pathname.indexOf('_'));
                if (pathname === '') {
                    if ($that[0].href.substring($that[0].href.indexOf('/post')) === location.pathname) {
                        $that.addClass('tab-this').siblings().removeClass('tab-this');
                    }
                } else {
                    if ($that[0].href.substring($that[0].href.indexOf('/post')) === pathname) {
                        $that.addClass('tab-this').siblings().removeClass('tab-this');
                    } else {
                        $that.parent('span').find('a').eq(0).addClass('tab-this').siblings().removeClass('tab-this');
                    }
                }
            });
        });
    </script>
}

